﻿namespace Pps.Gui.Base
{
    using System;
    using System.Collections;
    using System.Diagnostics;

    /// <summary>
    /// Container for <see cref="Pps.Gui.Base.DisplayObject"/>
    /// </summary>
    [Serializable]
    [DebuggerDisplay("Count = {Count}")]
    public sealed class DisplayObjectCollection : ICollection, IEnumerable, ICloneable
    {
        private ArrayList controls = new ArrayList();

        /// <summary>
        /// Adds the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        internal int Add(DisplayObject value)
        {
            return this.controls.Add(value);
        }

        /// <summary>
        /// Clears this instance.
        /// </summary>
        internal void Clear()
        {
            this.controls.Clear();
        }

        /// <summary>
        /// Determines whether a specific <see cref="DisplayObject"/> is in the collection.
        /// </summary>
        /// <param name="value">DisplayObject</param>
        /// <returns>True if the given object is in the collection.</returns>
        public bool Contains(DisplayObject value)
        {
            return this.controls.Contains(value);
        }

        public int IndexOf(DisplayObject value)
        {
            return this.controls.IndexOf(value);
        }

        internal void Insert(int index, DisplayObject value)
        {
            this.controls.Insert(index, value);
        }

        public bool IsFixedSize
        {
            get { return this.controls.IsFixedSize; }
        }

        public bool IsReadOnly
        {
            get { return this.controls.IsReadOnly; }
        }

        /// <summary>
        /// Removes the specified <see cref="DisplayObject"/>.
        /// </summary>
        /// <param name="value">DisplayObject</param>
        internal void Remove(DisplayObject value)
        {
            this.controls.Remove(value);
        }

        internal void RemoveAt(int index)
        {
            this.controls.RemoveAt(index);
        }

        public DisplayObject this[int index]
        {
            get
            {
                return (DisplayObject)this.controls[index];
            }
            internal set
            {
                this.controls[index] = value;
            }
        }

        public void CopyTo(Array array, int index)
        {
            this.controls.CopyTo(array, index);
        }

        /// <summary>
        /// Gets the number of elements contained in the <see cref="T:System.Collections.ICollection" />.
        /// </summary>
        /// <returns>The number of elements contained in the <see cref="T:System.Collections.ICollection" />.</returns>
        public int Count
        {
            get { return this.controls.Count; }
        }

        public bool IsSynchronized
        {
            get { return this.controls.IsSynchronized; }
        }

        public object SyncRoot
        {
            get { return this.controls.SyncRoot; }
        }

        public IEnumerator GetEnumerator()
        {
            return this.controls.GetEnumerator();
        }

        public object Clone()
        {
            return this.controls.Clone();
        }
    }
}